from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-27 14:02:12.117311
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 27, May, 2022
Time: 14:02:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4386
Nobs: 669.000 HQIC: -49.8099
Log likelihood: 8286.53 FPE: 1.84441e-22
AIC: -50.0447 Det(Omega_mle): 1.61386e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307935 0.059793 5.150 0.000
L1.Burgenland 0.107515 0.038630 2.783 0.005
L1.Kärnten -0.109647 0.020302 -5.401 0.000
L1.Niederösterreich 0.199886 0.080381 2.487 0.013
L1.Oberösterreich 0.125880 0.079574 1.582 0.114
L1.Salzburg 0.255683 0.041075 6.225 0.000
L1.Steiermark 0.044389 0.053836 0.825 0.410
L1.Tirol 0.104580 0.043581 2.400 0.016
L1.Vorarlberg -0.062420 0.038472 -1.622 0.105
L1.Wien 0.030941 0.070438 0.439 0.660
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.039785 0.127184 0.313 0.754
L1.Burgenland -0.029697 0.082169 -0.361 0.718
L1.Kärnten 0.040436 0.043185 0.936 0.349
L1.Niederösterreich -0.180426 0.170977 -1.055 0.291
L1.Oberösterreich 0.445870 0.169260 2.634 0.008
L1.Salzburg 0.284446 0.087370 3.256 0.001
L1.Steiermark 0.108511 0.114514 0.948 0.343
L1.Tirol 0.314775 0.092701 3.396 0.001
L1.Vorarlberg 0.022131 0.081834 0.270 0.787
L1.Wien -0.038214 0.149828 -0.255 0.799
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184204 0.030701 6.000 0.000
L1.Burgenland 0.089985 0.019835 4.537 0.000
L1.Kärnten -0.007906 0.010424 -0.758 0.448
L1.Niederösterreich 0.256170 0.041272 6.207 0.000
L1.Oberösterreich 0.155118 0.040858 3.797 0.000
L1.Salzburg 0.043169 0.021090 2.047 0.041
L1.Steiermark 0.024798 0.027643 0.897 0.370
L1.Tirol 0.085523 0.022377 3.822 0.000
L1.Vorarlberg 0.052688 0.019754 2.667 0.008
L1.Wien 0.117261 0.036167 3.242 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108721 0.030773 3.533 0.000
L1.Burgenland 0.045754 0.019881 2.301 0.021
L1.Kärnten -0.014020 0.010449 -1.342 0.180
L1.Niederösterreich 0.184486 0.041369 4.460 0.000
L1.Oberösterreich 0.327430 0.040954 7.995 0.000
L1.Salzburg 0.101551 0.021140 4.804 0.000
L1.Steiermark 0.109559 0.027707 3.954 0.000
L1.Tirol 0.097284 0.022430 4.337 0.000
L1.Vorarlberg 0.060375 0.019800 3.049 0.002
L1.Wien -0.022183 0.036252 -0.612 0.541
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114776 0.057187 2.007 0.045
L1.Burgenland -0.044384 0.036946 -1.201 0.230
L1.Kärnten -0.046129 0.019417 -2.376 0.018
L1.Niederösterreich 0.139940 0.076878 1.820 0.069
L1.Oberösterreich 0.164135 0.076106 2.157 0.031
L1.Salzburg 0.281190 0.039285 7.158 0.000
L1.Steiermark 0.055451 0.051490 1.077 0.282
L1.Tirol 0.164942 0.041682 3.957 0.000
L1.Vorarlberg 0.095617 0.036796 2.599 0.009
L1.Wien 0.076608 0.067368 1.137 0.255
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057728 0.045179 1.278 0.201
L1.Burgenland 0.032237 0.029188 1.104 0.269
L1.Kärnten 0.051657 0.015340 3.367 0.001
L1.Niederösterreich 0.205390 0.060735 3.382 0.001
L1.Oberösterreich 0.318226 0.060125 5.293 0.000
L1.Salzburg 0.041006 0.031036 1.321 0.186
L1.Steiermark 0.009214 0.040678 0.227 0.821
L1.Tirol 0.132042 0.032929 4.010 0.000
L1.Vorarlberg 0.066360 0.029069 2.283 0.022
L1.Wien 0.086712 0.053222 1.629 0.103
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164829 0.053991 3.053 0.002
L1.Burgenland 0.008449 0.034881 0.242 0.809
L1.Kärnten -0.065013 0.018332 -3.546 0.000
L1.Niederösterreich -0.091766 0.072581 -1.264 0.206
L1.Oberösterreich 0.204532 0.071852 2.847 0.004
L1.Salzburg 0.053835 0.037089 1.451 0.147
L1.Steiermark 0.241371 0.048612 4.965 0.000
L1.Tirol 0.502571 0.039352 12.771 0.000
L1.Vorarlberg 0.059594 0.034739 1.715 0.086
L1.Wien -0.076443 0.063603 -1.202 0.229
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.145237 0.060035 2.419 0.016
L1.Burgenland 0.003547 0.038786 0.091 0.927
L1.Kärnten 0.060321 0.020384 2.959 0.003
L1.Niederösterreich 0.182047 0.080706 2.256 0.024
L1.Oberösterreich -0.056631 0.079896 -0.709 0.478
L1.Salzburg 0.206183 0.041241 4.999 0.000
L1.Steiermark 0.135775 0.054054 2.512 0.012
L1.Tirol 0.070973 0.043758 1.622 0.105
L1.Vorarlberg 0.143881 0.038628 3.725 0.000
L1.Wien 0.110217 0.070723 1.558 0.119
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.372834 0.035439 10.520 0.000
L1.Burgenland -0.000219 0.022896 -0.010 0.992
L1.Kärnten -0.021936 0.012033 -1.823 0.068
L1.Niederösterreich 0.214853 0.047641 4.510 0.000
L1.Oberösterreich 0.227567 0.047163 4.825 0.000
L1.Salzburg 0.039332 0.024345 1.616 0.106
L1.Steiermark -0.014687 0.031908 -0.460 0.645
L1.Tirol 0.095875 0.025830 3.712 0.000
L1.Vorarlberg 0.054190 0.022802 2.377 0.017
L1.Wien 0.033847 0.041748 0.811 0.418
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037867 0.120847 0.176879 0.145425 0.103951 0.088518 0.042516 0.214026
Kärnten 0.037867 1.000000 -0.019016 0.135217 0.052836 0.091232 0.441915 -0.059274 0.094081
Niederösterreich 0.120847 -0.019016 1.000000 0.323920 0.131623 0.283920 0.077833 0.163449 0.302341
Oberösterreich 0.176879 0.135217 0.323920 1.000000 0.221696 0.311224 0.171451 0.153259 0.253588
Salzburg 0.145425 0.052836 0.131623 0.221696 1.000000 0.131814 0.100143 0.115874 0.131692
Steiermark 0.103951 0.091232 0.283920 0.311224 0.131814 1.000000 0.143152 0.121525 0.054700
Tirol 0.088518 0.441915 0.077833 0.171451 0.100143 0.143152 1.000000 0.072989 0.150992
Vorarlberg 0.042516 -0.059274 0.163449 0.153259 0.115874 0.121525 0.072989 1.000000 0.009633
Wien 0.214026 0.094081 0.302341 0.253588 0.131692 0.054700 0.150992 0.009633 1.000000